package com.atguigu.atcrowdfunding.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.atguigu.atcrowdfunding.bean.TProject;
import com.atguigu.atcrowdfunding.bean.TProjectExample;
import com.atguigu.atcrowdfunding.bean.TProjectExample.Criteria;
import com.atguigu.atcrowdfunding.mapper.TProjectMapper;
import com.atguigu.atcrowdfunding.service.TProjectService;
import com.atguigu.atcrowdfunding.util.AppDateUtils;
import com.github.pagehelper.PageInfo;

@Service
public class TProjectServiceImpl implements TProjectService {

	@Autowired
	TProjectMapper projectMapper;
	
	@Override
	public PageInfo<TProject> listUnauthProjectPage(Map<String, Object> paramMap) {
		String condition = (String) paramMap.get("condition");
		TProjectExample example = new TProjectExample();
		Criteria criteria = example.createCriteria().andStatusEqualTo("1");
		if (!"".equals(condition)) {
			criteria.andNameLike("%"+condition+"%");
		}
		example.setOrderByClause("createdate desc");
		List<TProject> list = projectMapper.selectByExample(example);
		PageInfo<TProject> page = new PageInfo<TProject>(list,5);
		return page;
	}

	@Override
	public void authProject(Integer projectId) {
		TProject project = new TProject();
		project.setId(projectId);
		project.setStatus("3");
		project.setDeploydate(AppDateUtils.getFormatTime());
		projectMapper.updateByPrimaryKeySelective(project);
	}

}
